<!-- 用户管理 -->
<template>
  <div class="app-container">
    <div class="disease-body">
      <el-card shadow="never" class="disease-left">
        <div class="disease-document" @click="openDialog">
          <img src="../../../assets/images/w01.png" alt="" />
          <div>点击上传</div>
        </div>
        <upload :postDetail="uploadDetail" @update-visible="closeDialog" />
        <div class="button-top">
          <top />
        </div>
        <el-card shadow="never" class="analysis-content" v-if="!isShow">
          <div class="analysis-container">
            <div class="analysis-img">
              <img src="../../../assets/images/a01.png" alt="" />
            </div>
            <div class="analysis-right">
              <div class="analysis-title">文档总结</div>
              <div class="analysis-text">
                上传一篇文档，可以针对文档内容进行问题解答，迎接更智能、、更直观的处理文档方式
              </div>
            </div>
          </div>
        </el-card>
        <div class="disease-message" v-else>
          <Message
            :obj="messageObj"
            @done="reloadHis"
            :params="messageParam"
            :knowledgeId="knowledgeId"
            @re-chat="getMessage"
          />
        </div>
        <div class="disease-bottom">
          <ChatFrame v-model="done" :postDetail="message" @send="send" />
        </div>
      </el-card>
      <!-- 右侧历史记录 -->
      <div class="disease-right">
        <History
          ref="refChild"
          @update-message="handlerHistory"
          :category="category"
          :bridgeType="bridgeType"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useBridgeStore } from "@/store";
import History from "../components/history.vue";
import Top from "../components/top.vue";
import upload from "../components/upload.vue";
import { useUserStore } from "@/store";

defineOptions({
  name: "DocumentSummary",
  inheritAttrs: false,
});
const userStore = useUserStore();
const isShow = ref(false);

const category = ref("4");
const knowledgeId = ref<string>(userStore.user.sysUser?.id);
// 聊天是否完成
const done = ref(false);
// 当前页面传给页面底部对话框的参数
const message = ref("");
// 历史记录传过来的messageId和messageTitle接收并传到message组件
const messageObj = ref({});
// 这里类似vuex
const bridgeStore = useBridgeStore();
// 导航选中的桥梁类型
const bridgeType = computed(() => bridgeStore.bridgeType);
// 获取子组件的引用
const refChild = ref(null);
// 文件上传弹框参数
const uploadDetail = ref({
  show: false,
  category: category,
});
// 打开弹框
function openDialog() {
  uploadDetail.value.show = true;
}
// 关闭弹框
function closeDialog(value) {
  uploadDetail.value.show = value;
}
// 聊天记录保存参数
const messageParam = reactive({
  bridgeType: bridgeStore.bridgeType,
  category: category,
  diseaseType: "",
});

// 接收历史记录组件传过来的问题描述并赋值到页面底部的对话框
function handlerHistory(x, y) {
  // 问答被终止
  done.value = false;
  if (x) {
    messageObj.value = {
      messageTitle: x.remark + "&",
      messageId: x.id,
    };
    // 如果x有值则打开对话框
    isShow.value = true;
  } else {
    // 否则关掉对话框
    isShow.value = false;
  }
}

function getMessage(x) {
  message.value = x;
}

// 调用历史记录列表刷新列表
function reloadHis() {
  done.value = false;
  refChild.value.getData();
}

// 点击发送按钮
function send(value: string) {
  message.value = value;
  messageObj.value = {
    messageTitle: value,
  };
  isShow.value = true;
}
</script>

<style lang="scss" scoped>
.disease-body {
  display: flex;
  font-size: var(--el-font-size-base);

  .disease-left {
    position: relative;
    flex: 1;
    height: 100%;
    border: none;
    background-color: transparent;
    padding: 0px 120px 0 120px;

    .disease-document {
      position: absolute;
      top: 65px;
      right: 28px;
      width: 81px;
      height: 106px;
      background: linear-gradient(
        180deg,
        rgba(47, 67, 92, 0.1) 0%,
        rgba(7, 81, 178, 0.6) 100%
      );
      box-shadow: 0px 0px 20px 1px rgba(150, 192, 248, 0.4);
      border-radius: 7px 7px 7px 7px;
      border: 1px solid #8dc1fd;
      padding: 11px;
      text-align: center;
      font-weight: 500;
      color: #8dc1fd;
      cursor: pointer;
      img {
        width: 50px;
        height: 50px;
        margin: 0 auto;
      }
    }

    .analysis-content {
      width: 100%;
      height: calc(var(--body-height) - 202px);
      padding: 20px 0;
      display: flex;

      .analysis-container {
        display: flex;

        .analysis-img {
          width: 48px;
          height: 48px;
          margin-right: 18px;

          img {
            width: 100%;
            height: 100%;
          }
        }

        .analysis-right {
          .analysis-title {
            font-weight: 400;
            font-size: 36px;
            color: var(--el-text-color-secondary);
          }

          .analysis-text {
            font-weight: 400;
            color: var(--el-color-info-dark-2);
            margin: 20px 0 30px;
          }

          .analysis-message {
            font-weight: 400;
            color: var(--el-color-primary-dark-2);
            line-height: 30px;
          }
        }
      }
    }
    .analysis-upload {
      width: 100%;
      height: calc(100vh - 601px);
      padding: 20px 0;
      display: flex;
      margin-bottom: 40px;
    }

    .analysis-document {
      width: 100%;
      height: 260px;
      padding: 20px 0;
      display: flex;
      border: 1px dashed;
    }

    .disease-bottom {
      width: 100%;
      height: 157px;
      margin-top: 20px;
    }

    .button-top {
      position: absolute;
      right: 0px;
    }
  }

  .disease-right {
    width: 224px;
    height: calc(var(--body-height) - 20px);
  }

  .disease-message {
    height: calc(var(--body-height) - 262px);
  }
}
</style>
